// pages/epidemicsee/epidemicSee.js
const app = getApp();
var QQMapWX = require('../../../utils/qqmap-wx-jssdk.js');
var WxParse = require('../../../wxParse/wxParse.js');
const util = require("../../../utils/util.js");
var qqmapsdk;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id:"",
    detail:"",
    time:"",
    cardType:0,
    name:"",
    tel:"",
    orgName:"",
    address:"",
    workingState:0,
    isTemperature:2,
    isCough:2,
    isSymptom:2,
    isStayedHotel:2,
    isMore: true,
    isMore2:true,
    isMore3: true,
    isMore4: true,
    isMore5:true,
    isLeaveAirplane:2,
    airplaneDate:"",
    airplaneNum:"",
    airplaneDate2: "",
    airplaneNum2: "",
    isBackAirplane: 2,
    trainDate: "",
    trainNum: "",
    trainDate2: "",
    trainNum2: "",
    isLeaveTrain: 2,
    subwayDate: "",
    subwayNum: "",
    subwayDate2: "",
    subwayNum2: "",
    isBackTrain: 2,
    busDate: "",
    busNum: "",
    busDate2: "",
    busNum2: "",
    isOthers: 2,
    othersDate: "",
    othersNum: "",
    othersDate2: "",
    othersNum2: "",
    ismodal:false,
    workingDateS: '',
    workingDate:'',
    login:false,
    loginShow:false,
    phoneshow:false,
    count:0,
    isDuty:0,
    lock:false,
  },
  toPage(e){
    var that = this;
    var dataset = e.currentTarget.dataset;
    var url = dataset.url + '?id=' + that.data.id;
    wx.navigateTo({
      url: url
    })
  },
  toggle(type, val) {
    this.setData({
      [type]: val
    });
  },
  setTrue(e){
    if(this.data.isDetail){
      return
    }
    var key = e.currentTarget.dataset.key;
    if (e.currentTarget.dataset.sign){
      var sign = e.currentTarget.dataset.sign;
    }
    this.toggle(key, 1);
    this.toggle(sign, 1);
  },
  setFalse(e) {
    if (this.data.isDetail) {
      return
    }
    var key = e.currentTarget.dataset.key;
    this.toggle(key, 0)
    if (key == 'isTemperature'){
      this.toggle('temperature', '')
    }
    if (key == 'workingState' || key == 'cardType') {
      this.toggle(key, 2)
    }
    // if (key == 'isLeaveAirplane') {
    //   this.toggle('isMore', true)
    // } else if (key == 'isBackAirplane'){
    //   this.toggle('isMore2', true)
    // } else if (key == 'isLeaveTrain') {
    //   this.toggle('isMore3', true)
    // } else if (key == 'isBackTrain') {
    //   this.toggle('isMore4', true)
    // } else if (key == 'isOthers') {
    //   this.toggle('isMore5', true)
    // }
  },
  setThred(e){
    if (this.data.isDetail) {
      return
    }
    var key = e.currentTarget.dataset.key;
    this.toggle(key, 3)
  },
  getTime() {
    var year = new Date().getFullYear();
    var month = new Date().getMonth() + 1;
    var day = new Date().getDate();
    var date = year + "年" + month + "月" + day + "日";
    var today = new Date().format("yyyy-MM-dd");
    this.toggle("time", date);
    this.toggle("today", today);

    var time = new Date().getTime() - 13 * 24 * 60 * 60 * 1000;
    var time2 = new Date().getTime();
    var yesToday = new Date(time).format("yyyy-MM-dd");
    var past = new Date(time);
    var past2 = new Date(time2);
    var pastDate = past.getMonth() + 1 + "月" + past.getDate() + "日";
    var pastDate2 = past2.getMonth() + 1 + "月" + past2.getDate() + "日";
    this.toggle("pastDate", pastDate);
    this.toggle("pastDate2", pastDate2);
    this.toggle("yesToday", yesToday); 
  },
  input(e){
    console.log(e);
    var key = e.currentTarget.dataset.key;
    // var top = e.currentTarget.dataset.top;
    if (key == "familyTemperature" || key == "temperature"){
      if (e.detail.value % 1 === 0){
        if (e.detail.value[2] == "."){
        }else{
          e.detail.value = e.detail.value.substring(0, 2);
        }
      }else{
        e.detail.value = parseFloat(e.detail.value).toFixed(1);
      }
      console.log(e.detail.value)
    }
    this.toggle(key, e.detail.value)
    // this.toggle(top, e.target.offsetTop)
  },
  bindfocus(){
    this.toggle('click', true)
  },
  bindblur(){
    this.toggle('click', false)
  },
  bindDateChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    var key = e.currentTarget.dataset.key;
    var backKey = e.currentTarget.dataset.backkey;
    var date = e.detail.value;
    this.toggle(key, date)
    this.toggle(backKey, e.detail.value + " 00:00:00")
  },
  changeMore(e){
    var key = e.currentTarget.dataset.key;
    if (key == 'isMore'){
      this.toggle('isMore', !this.data.isMore)
    } else if (key == 'isMore2'){
      this.toggle('isMore2', !this.data.isMore2)
    } else if (key == 'isMore3') {
      this.toggle('isMore3', !this.data.isMore3)
    } else if (key == 'isMore4') {
      this.toggle('isMore4', !this.data.isMore4)
    } else if (key == 'isMore5') {
      this.toggle('isMore5', !this.data.isMore5)
    }
  },
  //获取授权
  judgeAuthorization(e) {
    var click='';
    if(e){
      click = e.currentTarget.dataset.click;
    }
    var that = this;
    wx.getSetting({
      success(res) {
        //首次调起授权
        if (res.authSetting['scope.userLocation']) {
          wx.showToast({
            title: '',
            icon: 'loading'
          });
          that.openMap(click)
        } else {
          //手动授权
          wx.authorize({
            scope: 'scope.userLocation',
            success() {
              wx.showToast({
                title: '',
                icon: 'loading'
              });
              that.openMap(click)
            },
            fail() {
              wx.showModal({
                title: '提示',
                showCancel:false,
                content: '检测到您未授权一起来往获取您的位置信息，是否前往设置？',
                success(res) {
                  if (res.confirm) {
                    wx.openSetting({
                      complete(res) {
                        if (res.authSetting['scope.userLocation']) {
                          that.openMap(click);
                        }
                      },
                    })
                  }
                }
              })
            }
          })
        }
      },
    })
  },
  //调起地图组件
  openMap(click) {
    var that = this;
    wx.getLocation({
      type: 'gcj02',
      success(res) {
        wx.hideToast();
        var latitude = res.latitude;
        var longitude = res.longitude;
        that.toggle("latitude", latitude);
        that.toggle("longitude", longitude);
        qqmapsdk.reverseGeocoder({
          location: {
            latitude: latitude,
            longitude: longitude
          },
          success: function (res) {
            console.log('获取当前地址',res)
            if (res.status == 0 && res.result.address){
              that.toggle("address", res.result.address)
              that.toggle("city", res.result.address_component.city)
            }
            if (click){
              console.log('点击')
            }else{
              console.log('不点击')
              that.getInfo();
            }
          },
          fail: function (res) {
            console.log(res);
          },
        });

      },
      fail: function (res) {
        console.log('地图getLocation失败',res)
        wx.hideToast();
        wx.showModal({
          title: '',
          content: '无法获取你的位置信息。请到手机系统的[设置]->[隐私]->[定位服务]中打开定位服务，并允许微信使用定位服务。',
          showCancel: false,
          confirmText: '确定',
          success: function (res) {
          }
        })
      }
    })
  },
  // 获取头图
  getImg() {
    var that = this
    app.req({
      url: "wechat/activity/getPictureListByType",
      method: "post",
      data: {
        type: 26,
        pageSize: 10,
        pageNumber: 1
      },
      success: function (res) {
        if (200 == res.code) {
          console.log("获取相册列表", res)
          that.setData({
            imageUrl: res.data.rows
          })
          wx.hideLoading()
        } else {
          wx.hideLoading()
          wx.showToast({
            title: res.msg,
            icon: 'none',
            duration: 2000
          })
        }
      }
    })
  },
  detail: function () {
    var that = this;
    app.req({
      url: "orgmini/epidemic/epidemicRelation",
      data: {
        relationId: that.data.id,
        type:1,
      },
      success: function (res) {
        if (200 == res.code) {
          that.toggle("detail", res.data);
          that.toggle("name", res.data.name); 
          that.toggle("tel", res.data.tel); 
        }
      }
    });
  },
  // 拉取字典项
  getDistance(){
    var that = this;
    app.req({
      url: "orgmini/dictionary/listBydictType",
      data: {
        dictType: "RESUMPTION_WORK_SCOPE",
      },
      success: function (res) {
        if (200 == res.code) {
          that.toggle('distance', res.data[0].dictValue)
        }
      }
    });
  },
  timeDeal(time1, time2) {
    console.log(time1, time2)
    var a = time1.split(":");
    var b = time2.split(":");
    return new Date().setHours(a[0], a[1]) >= new Date().setHours(b[0], b[1])
  },
  // 提交数据
  submit(){
    var that = this;
    if (this.data.ismodal){
      return
    }
    if(that.data.lock){
      return
    }
    that.toggle('lock', true);
    var timeoutflag = null;
    if (timeoutflag != null) {
      clearTimeout(timeoutflag);
    }
    timeoutflag = setTimeout(function () {
      that.toggle('lock',false);
    }, 3000);
    var title = false;
    var phonePattern = /^((\d{3}-\d{8}|\d{4}-\d{7,8})|(1[3|4|5|6|7|8|9][0-9]{9}))$/;
    if (that.data.cardType == 0) {
      title = "请选择打卡时间段";
    } else if (!that.data.name) {
      title = "请输入姓名";
    } else if (!that.data.tel){
      title = "请输入联系方式";
    } else if (!phonePattern.test(that.data.tel)) {
      title = "请输入正确的手机号";
    } else if (!that.data.orgName) {
      title = "请输入单位或部门名称";
    } else if (!that.data.address) {
      title = "当前位置为空";
    } else if (that.data.workingState == 0) {
      title = "请选择工作状态";
    } else if ((that.data.workingState == 2 || that.data.workingState == 3) && !that.data.workingDate) {
      title = "请设置预计到岗日期";
    } else if (that.data.isTemperature == 2) {
      title = "请选择个人健康状况体温";
    } else if (that.data.isTemperature == 1 && !that.data.temperature) {
      title = "请输入个人健康状况体温";
    } else if (that.data.isCough == 2) {
      title = "请选择个人健康状况咳嗽";
    } else if (that.data.isSymptom == 2) {
      title = "请选择个人健康状况其他症状";
    } else if (that.data.isSymptom == 1 && !that.data.symptomInfo) {
      title = "请输入个人健康状况其他症状描述";
    } else if (!that.data.liveCity) {
      title = "请输入过去14日内旅居过的城市";
    } else if (that.data.isStayedHotel == 2) {
      title = "请选择过去14日内是否住过酒店";
    } else if (that.data.isStayedHotel == 1 && !that.data.stayedHotel) {
      title = "请输入酒店名称";
    } else if (that.data.isLeaveAirplane == 2) {
      title = "请选择过去14日内所搭乘过的交通工具去程飞机";
    } else if (that.data.isLeaveAirplane == 1 && !that.data.airplaneDate && !that.data.airplaneDate2 && that.data.count == 0) {
      title = "请输入搭乘去程飞机日期";
    } else if (that.data.isLeaveAirplane == 1 && !that.data.airplaneNum && !that.data.airplaneNum2) {
      title = "请输入去程飞机航班号";
    } else if (that.data.isBackAirplane == 2) {
      title = "请选择过去14日内所搭乘过的交通工具返程飞机";
    } else if (that.data.isBackAirplane == 1 && !that.data.trainDate && !that.data.trainDate2 && that.data.count == 0) {
      title = "请输入搭乘返程飞机日期";
    } else if (that.data.isBackAirplane == 1 && !that.data.trainNum && !that.data.trainNum2) {
      title = "请输入返程飞机航班号";
    } else if (that.data.isLeaveTrain == 2) {
      title = "请选择过去14日内所搭乘过的交通工具去程火车";
    } else if (that.data.isLeaveTrain == 1 && !that.data.subwayDate && !that.data.subwayDate2 && that.data.count == 0) {
      title = "请输入搭乘去程火车日期";
    } else if (that.data.isLeaveTrain == 1 && !that.data.subwayNum && !that.data.subwayNum2) {
      title = "请输入去程火车车次";
    } else if (that.data.isBackTrain == 2) {
      title = "请选择过去14日内所搭乘过的交通工具返程火车";
    } else if (that.data.isBackTrain == 1 && !that.data.busDate && !that.data.busDate2 && that.data.count == 0) {
      title = "请输入搭乘返程火车日期";
    } else if (that.data.isBackTrain == 1 && !that.data.busNum && !that.data.busNum2) {
      title = "请输入返程火车车次";
    } else if (that.data.isOthers == 2) {
      title = "请选择是否有其他行程";
    } else if (that.data.isOthers == 1 && !that.data.othersDate && !that.data.othersDate2 && that.data.count == 0) {
      title = "请输入其他行程出行日期";
    } else if (that.data.isOthers == 1 && !that.data.othersNum && !that.data.othersNum2) {
      title = "请输入出行方式";
    } else if (that.data.hasChange && that.data.isLeaveAirplane == 0 && that.data.isBackAirplane == 0 && that.data.isLeaveTrain == 0 && that.data.isBackTrain == 0 && that.data.isOthers == 0 ) {
      title = "您当前地址已发生变化，请选择至少一项交通工具";
    } else {
      title = false;
    }
    if (title){
      wx.showToast({
        title: title,
        icon: 'none',
        duration: 2000,
      })
      return
    }
    var journeyEntityList = [];
    if (that.data.airplaneDate || that.data.airplaneNum){
      journeyEntityList.push({
        type:1,
        journeyDate: that.data.airplaneDate,
        journeyTransport: that.data.airplaneNum,
      })
    }
    if (that.data.airplaneDate2 || that.data.airplaneNum2) {
      journeyEntityList.push({
        type: 1,
        journeyDate: that.data.airplaneDate2,
        journeyTransport: that.data.airplaneNum2,
      })
    }
    if (that.data.trainDate || that.data.trainNum) {
      journeyEntityList.push({
        type: 2,
        journeyDate: that.data.trainDate,
        journeyTransport: that.data.trainNum,
      })
    }
    if (that.data.trainDate2 || that.data.trainNum2) {
      journeyEntityList.push({
        type: 2,
        journeyDate: that.data.trainDate2,
        journeyTransport: that.data.trainNum2,
      })
    }
    if (that.data.subwayDate || that.data.subwayNum) {
      journeyEntityList.push({
        type: 3,
        journeyDate: that.data.subwayDate,
        journeyTransport: that.data.subwayNum,
      })
    }
    if (that.data.subwayDate2 || that.data.subwayNum2){
      journeyEntityList.push({
        type: 3,
        journeyDate: that.data.subwayDate2,
        journeyTransport: that.data.subwayNum2,
      })
    }
    if (that.data.busDate || that.data.busNum) {
      journeyEntityList.push({
        type: 4,
        journeyDate: that.data.busDate,
        journeyTransport: that.data.busNum,
      })
    }
    if (that.data.busDate2 || that.data.busNum2) {
      journeyEntityList.push({
        type: 4,
        journeyDate: that.data.busDate2,
        journeyTransport: that.data.busNum2,
      })
    }
    if (that.data.othersDate || that.data.othersNum) {
      journeyEntityList.push({
        type: 5,
        journeyDate: that.data.othersDate,
        journeyTransport: that.data.othersNum,
      })
    }
    if (that.data.othersDate2 || that.data.othersNum2) {
      journeyEntityList.push({
        type: 5,
        journeyDate: that.data.othersDate2,
        journeyTransport: that.data.othersNum2,
      })
    }
    console.log(journeyEntityList)
    var addressArr = that.data.setInfo.rwSetupDetail
    if (that.data.workingState == 1 && that.data.cardType == 1) {
      for (var i in addressArr) {
        var long = util.GetDistance(that.data.latitude, that.data.longitude, addressArr[i].latitude, addressArr[i].longitude) * 1000
        console.log('距离', long)
        if (long <= that.data.distance) {
          that.toggle('isDuty', 1)
        }
      }
    }
    console.log('距离111111111', that.data.isDuty)
    var next = false;
    var time = new Date().getHours() + ':' + new Date().getMinutes();
    // 工作
    var workTimeF = that.timeDeal(time, that.data.setInfo.workFirstStart);
    var workTimeF1 = that.timeDeal(that.data.setInfo.workFirstEnd, time);
    var workTimeS = that.timeDeal(time, that.data.setInfo.workSecondStart);
    var workTimeS1 = that.timeDeal(that.data.setInfo.workSecondEnd, time);
    // 居家
    var homeTimeF = that.timeDeal(time, that.data.setInfo.homeFirstStart);
    var homeTimeF1 = that.timeDeal(that.data.setInfo.homeFirstEnd, time);
    var homeTimeS = that.timeDeal(time, that.data.setInfo.homeSecondStart);
    var homeTimeS1 = that.timeDeal(that.data.setInfo.homeSecondEnd, time);
    console.log(workTimeF, workTimeF1, workTimeS, workTimeS1, homeTimeF, homeTimeF1, homeTimeS, homeTimeS1)
    if (that.data.cardType == 1){
      if (that.data.setInfo.workStatus == 0 &&  workTimeF && workTimeF1){
        next = true;
      } else if (that.data.setInfo.workStatus == 1 && (workTimeF && workTimeF1 || workTimeS && workTimeS1)){
        next = true;
      }
    } else if (that.data.cardType == 2){
      if (that.data.setInfo.homeStatus == 0 && homeTimeF && homeTimeF1) {
        next = true;
      } else if (that.data.setInfo.homeStatus == 1 && (homeTimeF && homeTimeF1 || homeTimeS && homeTimeS1)) {
        next = true;
      }
    }
    console.log(next)

    if (!next){
      var cont = '';
      if (that.data.setInfo.workStatus == 0 && that.data.cardType == 1){
        cont = '工作打卡时间段为' + that.data.setInfo.workFirstStart + '-' + that.data.setInfo.workFirstEnd;
      }
      if (that.data.setInfo.workStatus != 0 && that.data.cardType == 1) {
        cont = '工作打卡时间段为' + that.data.setInfo.workFirstStart + '-' + that.data.setInfo.workFirstEnd + ',' + that.data.setInfo.workSecondStart + '-' + that.data.setInfo.workSecondEnd;
      }
      if (that.data.setInfo.homeStatus == 0 && that.data.cardType == 2) {
        cont = '居家打卡时间段为' + that.data.setInfo.homeFirstStart + '-' + that.data.setInfo.homeFirstEnd;
      }
      if (that.data.setInfo.homeStatus != 0 && that.data.cardType == 2) {
        cont = '居家打卡时间段为' + that.data.setInfo.homeFirstStart + '-' + that.data.setInfo.homeFirstEnd + ',' + that.data.setInfo.homeSecondStart + '-' + that.data.setInfo.homeSecondEnd;
      }
      wx.showModal({
        title: '',
        content: cont,
        confirmText: "再试一次",
        cancelText: '确认',
        success(res) {
          if (res.confirm) {
            console.log('用户点击确定')
            that.toggle('lock', false);
            that.submit();
          } else if (res.cancel) {
          }
        }
      })
      return
    }
    var timeInterval = '';
    if (workTimeF && workTimeF1 || homeTimeF && homeTimeF1){
      timeInterval = 1;
    } else if (workTimeS && workTimeS1 || homeTimeS && homeTimeS1){
      timeInterval = 2;
    }
    console.log(timeInterval);
    app.req({
      url: "orgmini/resumptionWork/save",
      method: "post",
      data: {
        "type": that.data.cardType,
        "orgId": that.data.id,
        'timeInterval': timeInterval,
        "posterUrl": that.data.imageUrl[0].url,
        "reportName": that.data.name,
        "reportTel": that.data.tel,
        "reportDept": that.data.orgName,
        "currentAddress": that.data.address,
        "latitude": that.data.latitude,
        "longitude": that.data.longitude,
        'workingState': that.data.workingState,
        "workingDate": that.data.workingState !=1 ? that.data.workingDate:'',
        "isTemperature": that.data.isTemperature,
        "temperature": that.data.temperature,
        "isCough": that.data.isCough,
        "isSymptom": that.data.isSymptom,
        "symptomInfo": that.data.symptomInfo,
        "liveCity": that.data.liveCity,
        "isStayedHotel": that.data.isStayedHotel,
        "stayedHotel": that.data.stayedHotel,
        "isLeaveAirplane": that.data.isLeaveAirplane,
        "isBackAirplane": that.data.isBackAirplane,
        "isLeaveTrain": that.data.isLeaveTrain,
        "isBackTrain": that.data.isBackTrain,
        "isOthers": that.data.isOthers,
        "remark": that.data.remark,
        "journeyEntityList": journeyEntityList,
        "isDuty": that.data.isDuty,
        "sourceType":1
      },
      success: function (res) {
        if (200 == res.code) {
          that.toggle('ismodal', true);
          wx.hideLoading()
          that.toggle('sign1', '');
          that.toggle('sign2', '');
          that.toggle('sign3', '');
          that.toggle('sign4', '');
          that.toggle('sign5', '');
        } else {
          wx.hideLoading()
          wx.showToast({
            title: res.msg,
            icon: 'none',
            duration: 2000
          })
        }
      }
    })
  },
  //详情获取数据,上次提交
  getInfo(){
    var that = this;
    var url = that.data.isDetail ? "orgmini/resumptionWork/detail" :"orgmini/resumptionWork/getDetail";
    app.req({
      url: url,
      method: "post",
      data: {
        id: that.data.isDetail ? that.data.listId : '',
        orgId: that.data.isDetail ? '' : that.data.id
      },
      success(res){
        if (!res.data){
          that.toggle('count',0)
        } else if (res.code == 200 && res.data){
          var detail = res.data;
          if (that.data.isDetail) {
            wx.setNavigationBarTitle({
              title: res.data.reportName + '详情'
            })
            that.toggle('cardType', res.data.type);
            that.toggle('temperature', res.data.temperature);
            that.toggle('isTemperature', res.data.isTemperature);
            // 居家打卡本地距离判断
            // if (res.data.type == 2){
            //   var long = util.GetDistance(that.data.latitude, that.data.longitude, res.data.latitude, res.data.longitude) * 1000
            //   console.log('距离获取', long)
            //   if (long <= that.data.distance) {
            //     that.toggle('focusOn',true)
            //   }
            // }
            that.toggle("address", res.data.currentAddress);
          }
          if (res.data.createTime.substring(0, 10) == that.data.today) {
            that.toggle('isToday', true);
          }
          if (res.data.createTime && that.data.isDetail) {
            var t = res.data.createTime.split(' ');
            var time = t[0].split('-')[0] + '年' + parseInt(t[0].split('-')[1]) + '月' + parseInt(t[0].split('-')[2]) + '日 ' + t[1].substring(0, 5);
            that.toggle("time", time);
          }
          that.toggle('lastTime', res.data.createTime);
          that.toggle('count', res.data.count);
          that.toggle("name", res.data.reportName);
          that.toggle("tel", res.data.reportTel);
          that.toggle("orgName", res.data.reportDept);
          // 获取城市信息
          qqmapsdk.reverseGeocoder({
            location: {
              latitude: res.data.latitude,
              longitude: res.data.longitude
            },
            success: function (res) {
              console.log('获取上一次地址', res)
              var lCity = res.result.address_component.city;
              console.log('城市对比', lCity, that.data.city)
              if (!that.data.isDetail && lCity != that.data.city){
                that.toggle('hasChange',true);
              }else{
                that.toggle("isLeaveAirplane", detail.isLeaveAirplane);
                that.toggle("isBackAirplane", detail.isBackAirplane);
                that.toggle("isLeaveTrain", detail.isLeaveTrain);
                that.toggle("isBackTrain", detail.isBackTrain);
                that.toggle("isOthers", detail.isOthers);
                var list = detail.journeyEntityList;
                var air1 = [];var air2 = []; var air3 = []; var air4 = []; var air5 = [];
                if (that.data.count == 1 && !that.data.isDetail){
                }else{
                  if (list){
                    // 当前详情：count == 1 && isDetail
                    for (var i in list){
                      if (list[i].type == 1) {
                        air1.push(list[i])
                        if (air1.length == 1){
                          that.toggle("airplaneDateS", air1[0].journeyDate.substring(0, 10));
                          that.toggle("airplaneDate", air1[0].journeyDate);
                          that.toggle("airplaneNum", air1[0].journeyTransport);
                          WxParse.wxParse('rich2', 'md', air1[0].journeyTransport, that, 5);
                        }else{
                          that.toggle('isMore',false);
                          that.toggle("airplaneDateS", air1[0].journeyDate.substring(0, 10));
                          that.toggle("airplaneDate", air1[0].journeyDate);
                          that.toggle("airplaneNum", air1[0].journeyTransport);
                          that.toggle("airplaneDateS2", air1[1].journeyDate.substring(0, 10));
                          that.toggle("airplaneDate2", air1[1].journeyDate);
                          that.toggle("airplaneNum2", air1[1].journeyTransport);
                          WxParse.wxParse('rich2', 'md', air1[0].journeyTransport, that, 5);
                          WxParse.wxParse('rich22', 'md', air1[1].journeyTransport, that, 5);
                        }
                      }
                      if (list[i].type == 2) {
                        air2.push(list[i])
                        console.log('air2', air2)
                        if (air2.length == 1) {
                          that.toggle("trainDateS", air2[0].journeyDate.substring(0, 10));
                          that.toggle("trainDate", air2[0].journeyDate);
                          that.toggle("trainNum", air2[0].journeyTransport);
                          WxParse.wxParse('rich3', 'md', air2[0].journeyTransport, that, 5);
                        } else {
                          that.toggle('isMore2', false);
                          that.toggle("trainDateS", air2[0].journeyDate.substring(0, 10));
                          that.toggle("trainDate", air2[0].journeyDate);
                          that.toggle("trainNum", air2[0].journeyTransport);
                          that.toggle("trainDateS2", air2[1].journeyDate.substring(0, 10));
                          that.toggle("trainDate2", air2[1].journeyDate);
                          that.toggle("trainNum2", air2[1].journeyTransport);
                          WxParse.wxParse('rich3', 'md', air2[0].journeyTransport, that, 5);  
                          WxParse.wxParse('rich32', 'md', air2[1].journeyTransport, that, 5);
                        }
                      }
                      if (list[i].type == 3) {
                        air3.push(list[i])
                        if (air3.length == 1) {
                          that.toggle("subwayDateS", air3[0].journeyDate.substring(0, 10));
                          that.toggle("subwayDate", air3[0].journeyDate);
                          that.toggle("subwayNum", air3[0].journeyTransport);
                          WxParse.wxParse('rich4', 'md', air3[0].journeyTransport, that, 5);
                        } else {
                          that.toggle('isMore3', false);
                          that.toggle("subwayDateS", air3[0].journeyDate.substring(0, 10));
                          that.toggle("subwayDate", air3[0].journeyDate);
                          that.toggle("subwayNum", air3[0].journeyTransport);
                          that.toggle("subwayDateS2", air3[1].journeyDate.substring(0, 10));
                          that.toggle("subwayDate2", air3[1].journeyDate);
                          that.toggle("subwayNum2", air3[1].journeyTransport);
                          WxParse.wxParse('rich4', 'md', air3[0].journeyTransport, that, 5);
                          WxParse.wxParse('rich42', 'md', air3[1].journeyTransport, that, 5);
                        }
                      }
                      if (list[i].type == 4) {
                        air4.push(list[i])
                        if (air4.length == 1) {
                          that.toggle("busDateS", air4[0].journeyDate.substring(0, 10));
                          that.toggle("busDate", air4[0].journeyDate);
                          that.toggle("busNum", air4[0].journeyTransport);
                          WxParse.wxParse('rich5', 'md', air4[0].journeyTransport, that, 5);
                        } else {
                          that.toggle('isMore4', false);
                          that.toggle("busDateS", air4[0].journeyDate.substring(0, 10));
                          that.toggle("busDate", air4[0].journeyDate);
                          that.toggle("busNum", air4[0].journeyTransport);
                          that.toggle("busDateS2", air4[1].journeyDate.substring(0, 10));
                          that.toggle("busDate2", air4[1].journeyDate);
                          that.toggle("busNum2", air4[1].journeyTransport);
                          WxParse.wxParse('rich5', 'md', air4[0].journeyTransport, that, 5);
                          WxParse.wxParse('rich52', 'md', air4[1].journeyTransport, that, 5);
                        }
                      }
                      if (list[i].type == 5) {
                        air5.push(list[i])
                        if (air5.length == 1) {
                          that.toggle("othersDateS", air5[0].journeyDate.substring(0, 10));
                          that.toggle("othersDate", air5[0].journeyDate);
                          that.toggle("othersNum", air5[0].journeyTransport);
                          WxParse.wxParse('rich6', 'md', air5[0].journeyTransport, that, 5);
                        } else {
                          that.toggle('isMore5', false);
                          that.toggle("othersDateS", air5[0].journeyDate.substring(0, 10));
                          that.toggle("othersDate", air5[0].journeyDate);
                          that.toggle("othersNum", air5[0].journeyTransport);
                          that.toggle("othersDateS2", air5[1].journeyDate.substring(0, 10));
                          that.toggle("othersDate2", air5[1].journeyDate);
                          that.toggle("othersNum2", air5[1].journeyTransport);
                          WxParse.wxParse('rich6', 'md', air5[0].journeyTransport, that, 5);
                          WxParse.wxParse('rich62', 'md', air5[1].journeyTransport, that, 5);
                        }
                      }
                    }
                  }
                }
                console.log('处理交通',air2, air3)
              }
            },
            fail: function (res) {
              console.log(res);
            },
          });
          that.toggle("workingState", res.data.workingState);
          that.toggle("workingDateS", res.data.workingDate.substring(0, 10));
          that.toggle("workingDate", res.data.workingDate);
          that.toggle("isCough", res.data.isCough);
          that.toggle("isSymptom", res.data.isSymptom);
          that.toggle("symptomInfo", res.data.symptomInfo);
          WxParse.wxParse('rich', 'md', res.data.liveCity, that, 5);
          that.toggle("liveCity", res.data.liveCity);
          that.toggle("isStayedHotel", res.data.isStayedHotel);
          WxParse.wxParse('rich1', 'md', res.data.stayedHotel, that, 5);
          that.toggle("stayedHotel", res.data.stayedHotel);
          that.toggle("remark", res.data.remark);
        }
      }
    })
  },
  preventTouchMove() {},
  cancel() {
    this.toggle("ismodal", false);
    this.getInfo();
  },
  // 登录
  login() {
    this.toggle('loginShow', true);
    this.selectComponent('#login').showClose();
  },
  loginClose() {
    this.toggle('loginShow', false)
  },
  toggleToast(e) {
    console.log(e.detail);
    if (!e.detail.loginShow) {
      this.toggle('loginShow', false)
    }
    this.getUser()
  },
  toggleToast1(e) {
    console.log(e.detail)
    if (!e.detail.phoneshow) {
      this.toggle('phoneshow', false)
    }
    this.getUser()
  },
  getUser(){
    var that = this;
    wx.getSetting({
      success(res) {
        // if (!res.authSetting['scope.userInfo'] || wx.getStorageSync('uid') == '') {
        if (wx.getStorageSync('uid') == '') {
          that.toggle("login", false);
          that.login();
        } else {
          that.toggle("login", true);
          that.detail();
          if(!that.data.isDetail){
            that.getSetInfo();
            that.judgeAuthorization();
          }else{
            that.getInfo();
          }
          app.getUserInfo(function (userInfo) {
            that.toggle("avatarImg", userInfo.avatarUrl);
          });
        }
      },
    })
  },
  // 获取设置详情
  getSetInfo() {
    var that = this;
    var url = "orgmini/rwSetup/setupInfo";
    app.req({
      url: url,
      method: "post",
      data: {
        orgId: that.data.id
      },
      success(res) {
        console.log(res)
        if (res.code == 200 && res.data) {
          that.toggle("setInfo", res.data);
        }else{
          wx.showModal({
            title: '提示',
            content: '请先设置并保存，才可复工打卡',
            cancelText: "返回",
            confirmText: "设置",
            success(res) {
              if (res.confirm) {
                wx.redirectTo({
                  url: '/packageA/pages/epidemicSeeSet/epidemicSeeSet?id=' + that.data.id
                })
              } else if (res.cancel) {
                wx.redirectTo({
                  url: '/pages/orgHome/orgHome?id=' + that.data.id
                })
              }
            }
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log("复工打卡",options);
    qqmapsdk = new QQMapWX({
      key: 'GK5BZ-WXALX-7QC4N-7ZTQN-5VHKQ-5GFLF'
    });
    this.toggle("id", options.id);
    if (options.isOrg){
      this.toggle("isOrg", options.isOrg);
    }
    if (options.avaimg){
      this.toggle("avaimg", options.avaimg);
    }
    this.getDistance();
    // 详情
    if (options.isshow) {
      this.toggle("isDetail", true);
      this.toggle("listId", options.listid);
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getUser();
    // if(!this.data.isDetail){
    //   this.getSetInfo();
    // }
    this.getTime();
    this.getImg();

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    return true
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var title = ''
    var url = ''
    this.toggle("ismodal", false);
    title = this.data.detail.relationName + '邀请你用一起来往进行复工打卡'
    if (this.data.isOrg) {
      url = '/pages/orgHome/orgHome?id=' + this.data.id
    } else{
      url = '/pages/epidemicSee/epidemicSee?isorg=' + this.data.isOrg + '&id=' + this.data.id
    }
    return {
      title: title,
      imageUrl: this.data.imageUrl[0].url,
      path: url
    }
  }
})